//
//  GridCell.m
//  ios_news
//
//  Created by Han on 14-6-23.
//  Copyright (c) 2014年 ucoder. All rights reserved.
//

#import "GridCell.h"
#import "Util.h"

@implementation GridCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        //self.backgroundColor = [UIColor grayColor];
        [self drawView];
    }
    return self;
}

- (void) drawView
{
    
    UIView *rightSp = [[UIView alloc]initWithFrame:CGRectMake(self.frame.size.width-0.5, 0, 0.5, self.frame.size.height)];
    rightSp.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    [rightSp setBackgroundColor:UIColorFromRGB(0xCCCCCC)];
    [self addSubview:rightSp];
    
    UIView *bottom = [[UIView alloc]initWithFrame:CGRectMake(0, self.frame.size.height-0.5, self.frame.size.width, 0.5)];
    [bottom setBackgroundColor:UIColorFromRGB(0xCCCCCC)];
    
    [self addSubview:bottom];
    
    
    self.gridIcon = [[UIImageView alloc]initWithFrame:CGRectMake(35, 18, 30 ,30)];
    [self.gridIcon setContentMode:UIViewContentModeScaleAspectFit];
    [self addSubview:self.gridIcon];
    
    self.gridTitle = [[UILabel alloc]initWithFrame:CGRectMake(2, self.gridIcon.frame.size.height+15, self.frame.size.width-10, self.frame.size.height*0.5-10)];
    self.gridTitle.numberOfLines = 2;
    self.gridTitle.textColor = UIColorFromRGB(0x555555);
    
    [self.gridTitle setFont:[UIFont systemFontOfSize:12.0]];
    self.gridTitle.textAlignment = NSTextAlignmentCenter;
    [self.gridTitle setBackgroundColor:[UIColor clearColor]];

    [self addSubview:self.gridTitle];
}

- (void)setGrid:(Grid *)grid {
    //NSLog(@"%@", grid.iconTitle);
    
    [self.gridIcon setImage:[UIImage imageNamed:grid.iconImageName]];
    self.gridTitle.text = grid.iconTitle;
    
    /*
    if (grid.id == 1) {
        if ([Util isNightMode]) {
            [self.gridIcon setImage:[UIImage imageNamed:@"night"]];
            self.gridTitle.text = @"夜间";
        } else {
            [self.gridIcon setImage:[UIImage imageNamed:@"day"]];
            self.gridTitle.text = @"日间";
        }
        
    } else {
        [self.gridIcon setImage:[UIImage imageNamed:grid.iconImageName]];
        self.gridTitle.text = grid.iconTitle;
    }
     */
}

@end
